Repository navigation
Reimplement UpdateHealer and UpdateSpearman from gynt's units branch (100%) - #545
Merged
Merged
Conversation
Units::UpdateHealer at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the file: e368a00 at 47.79%, 2d6e422 at 57.41%, 794dcd1 at 57.61%, and the style commit 974c32f), through the forms on our development branches (94.1% there). What the match needed, against that text: - Behind the two searches for a plague cloud that have an else path, the original computes the unit's offset once, in front of the test (0x005405D5 and 0x005408EB: mov ecx, [slot]; imul ecx, ecx, 0x490; cmp eax, ebx), and both arms store through ecx. That is an if / else with the store both arms share written once behind it: animationCycleNumber at the first (0x00540611 and 0x0054064C are the two copies the compiler made of it), destinationNeeded at the second. The text had an early return in the first arm and the shared store in each arm, with a local copy of the slot at the first site; that loads the slot in front of the test and multiplies in each arm, and it changes the order of the stores. quick_diff with the group's callees in the unit: 0.9472 -> 0.9611 with the second site, 0.9782 with both. - The random number for the apothecary's choice is declared where the original masks it, behind the six stores (and edx, 7 at 0x005406EF, kept in esi over the call): at the top of the block it takes ebp. 0.9782 -> 0.9860, and what is left there is the same bytes written two ways (0xd8f0 and -0x2710, 0xff and -1). - The last exit stores the cloud's velocity in front of destinationNeeded, as the original does (0x00540CC6, 0x00540CCF), and the return that closed that arm is gone: with the two sites above written as they are, the arm falls out of the chain like the others (the same object code with and without it). Number casts to UnitState and the two numbers stored into cachedState are the enum's names, calls that return BOOLEnum are tested by truthiness, and the cloud's frame value 0x3f8 is decimal. disappearFadeAlphaCountdown and the frame tables are char and the random number is masked with 7, so the `(char)` and `(byte)` casts on them are gone. None of these changes the object code. `else if (random <= 7)` is always true behind `& 7`: the original tests it (0x00540763), a comment says so, and a plain else reads 0.9609. compiler-flags-gl.txt gets UpdateHealer.cpp only: the callees it has to see are on main's list already (quick_diff 0.6464 alone; without hasUnitReachedDestination 0.6867, checkIfCitizenUnitIsAliveBasedOnState 0.8556, hasTunnelerNotFinishedDigging 0.9633). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Units::UpdateSpearman at 100%, from Gynt's draft on sourcehold's reimpl/map-units-updatefunctions (his commits on the file: be18ccc at 38.12%, 0816e82 at 50.99%, 6565c1b, and the style commit 974c32f), through the forms on our development branches (93.6% there). What the match needed, against that text: - The call of UnitsState::returnFalseStub (0x00533090, `xor eax, eax; ret 4`, 100% on main). The original calls it where no ladder was found and keeps the slot in edx over the call (0x0055DE0E: push edx; mov ecx, <units>; call; imul edx, edx, 0x490), so it knew which registers the stub writes, and it did not drop the call. With the stub's body in the unit a call whose result nobody reads is dropped (as a plain function and with __declspec(noinline) alike), and with the body out of sight the slot is loaded again behind it. Tested in an if whose arms both store US_STATE_2Unk, the call stays, the test goes, and the code is the original's. A one-line comment says so. - The wall attack reads the tile's logic entry once into a local and tests the wall bit at each of its four uses (`logic & L_WALL_OR_GATEHOUSE`), in place of a local that held the masked value: the original loads the entry into edx, the building into esi, and only then masks into edi (0x0055E353 to 0x0055E364). 0.9581 -> 0.9668 in quick_diff with the callees named below in the unit. - The dig state ends as main's UpdatePikeman's does: the unit on the tile as `int const occupant`, and the two closing stores written in the arm for a finished tile and behind the block (once: 0.9668 against 0.9804). - The fill state's moat owner goes through a local for returnOwnedMoatAtTile's result, as in main's UpdateSlave (0.9804 -> 0.9826, where what is left is the same bytes written two ways: 0xffff and -1, `call esi` for the import, `test dl, bl`). - The warning's file name is main's s_General_Warning11_wav_005abe28 (the original pushes 0x005ABE28). Number casts to UnitState are the enum's names, the two moat bits and the wall bit are LogicHelpers' names, calls that return BOOLEnum and IsGateOrTowerArray are tested by truthiness, the damage of a hit on a building is an if / else (it was a ternary), every case ends in `return;`, and the casts that did nothing are gone (`(char)` on disappearFadeAlphaCountdown and the frame tables, `(short)` on BuildingLayer and on both operands of the dig tile's x): none of these changes the object code. advanceMoatDigProgress and removeMoat stay compared with 1, as in UpdatePikeman: a truth test reads 0.9811. The owner is read from the unit again where the original reads it again: in the test at 0x0055DF9F, as an argument of processDamageToBuildingThunk (0x0055E3D2), into the wall attack's `attacker` (0x0055E48C), and in the two tests at 0x0055EAC6 and 0x0055EB6C. Through the function's `owner` these read 0.9242, 0.9363, 0.8982, 0.9479 and 0.9240. The player's field at 0x2274 is written aiHoldBackTicks, the name main's PlayerData.hpp has for it since the header sync d134c77 (it was aiControlStatusRelated; same type, same offset): two lines, the same object code. compiler-flags-gl.txt gets UpdateSpearman.cpp only: xyAreValid, returnFalseStub, findAndDestroyAdjacentEnemyLadder, hasUnitReachedDestination and changeDestinationByAmount are on main's list already (quick_diff 0.5408 alone). Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…arman Two new entries, so that the two units read with OPENSHC_FUNCTION_VISIBILITY_UNITS on what they read in the default build. Both join the group that holds hasUnitReachedDestination. UpdateHealer names three callees, all members of that group already. UpdateSpearman names three members (xyAreValid, hasUnitReachedDestination, changeDestinationByAmount) and two /GL files from outside it, returnFalseStub and findAndDestroyAdjacentEnemyLadder, which join the group with it: no other .cpp calls either, so no other function sees a body it didn't see before or loses one. Each caller-callee pair is measured as sourcehold#491's were (quick_diff, the unit's file with the callee files pasted in front of it, against the unit alone). The callees tried are the group's members that the unit calls directly or through another member it calls; one is named when leaving it out lowers the ratio, and the named set reads what the whole set reads: - UpdateHealer 0.6464 alone, 0.9860 with its three: without hasUnitReachedDestination 0.6867, checkIfCitizenUnitIsAliveBasedOnState 0.8556, hasTunnelerNotFinishedDigging 0.9633. Not named (no change): commitUnitLocation, setupUnitSharingCurrentTilePosition, setupUnitSharingTileIDs, makeUnitStopWalkingByClearingPathProgressState. - UpdateSpearman 0.5408 alone, 0.9826 with its five: without hasUnitReachedDestination 0.5580, xyAreValid 0.9370, changeDestinationByAmount 0.9614 (each measured on the three members alone, which read 0.9637); with findAndDestroyAdjacentEnemyLadder on top of the three 0.9725, with returnFalseStub 0.9737. The original keeps the unit's offset in esi over the first (0x0055DF59, stores through esi at 0x0055DF63) and the slot in edx over the second (0x0055DE14, used at 0x0055DE19). On top of the named callees, each other /GL callee the unit calls was tried one at a time, without its own callees: none changes a ratio. What 0.9860 and 0.9826 leave are lines quick_diff writes two ways (0xffff and -1, an import called through a register); the builds in the pull request read the two units 100.0%. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
gynt
approved these changes
Dec 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Two more Map::Units update functions, from gynt's units branch
reimpl/map-units-updatefunctions(his draft #204). Both read 100.0% in the default build and with main's function-visibility option on. Each commit cites the commits of gynt's that measured the file and those that only touched its text.UpdateSlinger, which was worked on together with these two, is in #544, the other PR of this round: it uses two enum names that are a header change, so it travels with them. Neither PR needs the other.
Units::UpdateHealerUnits::UpdateSpearman"Before" is the status of gynt's last measured commit on each file; his later commits on them (6565c1b on UpdateSpearman, 974c32f on both) were not measured.
Measured.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed: the data resolvers withtools/reimplementation-control/enable_reimplemented_data.py, the function resolvers of the.cppfiles in the build), and sourcehold's reccmp (a86aceb03) with--resolve-wrapped-calls --ignore-security-cookie. Normalised is main'sreccmp_report.pyfigure, which ignores call and tail-jump targets and resolver addresses./GLfile of main; the two units and six of main's, UpdatePitchman, UpdateDairyFarmer, UpdateEngineer, UpdateFireBallista, UpdateCatapult and UpdateHopsFarmer, with their callee closures; every file of a function-visibility group that touches them), BUILD_OK and 0 failures in both modes. UpdateHealer and UpdateSpearman read 100.0% / 100.0% (raw / normalised) in both, and so do the callees their entries name. With the option on,cmake/function-visibility-units.pymakes 25 wrapper units, as on main; the two units,returnFalseStubandfindAndDestroyAdjacentEnemyLadderare in the one that holdshasUnitReachedDestination..cppin it. One of its renames reaches this PR:PlayerData::aiControlStatusRelatedisaiHoldBackTicksthere (same type, same offset), which UpdateSpearman reads in two lines; they are renamed in its commit. Both functions were then compiled on the tree the builds were made of and on the new head, three ways: the file alone, and with its callees pasted in front of it in the option-on layout and in the default one. In all three, each function's own section of the object file is the same, bytes and relocations, andquick_diffgives the same diff against the original in both layouts. So the builds were not repeated on the new main.giveMoveCommand,spawnUnit,isWorkerAtProductionIdleState,ifAnyUnitOnSameTileIsLadderInRightDirection,updateUnitFadeAndVisibilityNearStructuresandselectWorkerSpeechOrMoraleStateID(Reimplement six UnitsState functions at 100%, from gynt's text on main #539),processUnitAttackOtherUnit(Reimplement UnitsState::processUnitAttackOtherUnit at 100%, from gynt's text on main #542) and, with the option off,computeLadderClimbPath(Take UnitsState::clearAllUnits and computeLadderClimbPath off the /GL list (both back at 100%) #541).Buildings::UpdateCatapultBuildingreads 99.6% / 95.5% with the option off (99.6% / 95.7% in main's build) and 100.0% / 100.0% with it on, as in main's.UnitsState::processEntityDamageToUnitreads 71.5% / 67.9% with the option off and 77.3% / 69.0% with it on; main's builds have those two readings the other way round./GLfile of main is in the small builds, and only those files take part in link-time code generation. So the builds hold the two new bodies and every function whose code the new bodies could shift: the other callers of the callees they call (hasUnitReachedDestinationand the other members of its group, andreturnFalseStubandfindAndDestroyAdjacentEnemyLadder, which join that group). The files outside/GLare compiled one at a time and see none of the new bodies, and no.cppnames the two new functions.style_lint.py): nothing to fix automatically, no errors and 35 notes, all of the kinds under "Kept as they are" (11 casts, 22 placeholder names, one declaration without a value, one note on the mix of truth tests).What got them to 100%
The text started from his drafts and stood at 94.1% (UpdateHealer) and 93.6% (UpdateSpearman) on our development branches; each commit lists what changed, with the original's addresses. The last steps:
quick_diffwith the callees in the unit: 0.9472 -> 0.9611 -> 0.9782.returnFalseStub(UpdateSpearman). The original calls the stub (0x00533090,xor eax, eax; ret 4) where no ladder was found and keeps the slot inedxover the call (0x0055DE0E), so it saw the stub's body and still called it. In our build a call whose result nobody reads is dropped once the body is visible, and with the body out of sight the slot is loaded again. With the result tested in anifwhose arms both store the same state, the call stays and the test goes: the original's code. A comment says so. This is the form that parked the function at 93.6%.returnOwnedMoatAtTile's result, as in UpdateSlave.logic & L_WALL_OR_GATEHOUSEat each of its four uses; a local that held the masked value put the mask in front of the building's load (0x0055E353 to 0x0055E364). 0.9581 -> 0.9668.The entries
hasUnitReachedDestination. UpdateHealer names three of its members. UpdateSpearman names three members and two/GLfiles from outside the group,returnFalseStubandfindAndDestroyAdjacentEnemyLadder, which join it: no other.cppcalls either of them, so no other function sees a body it didn't see before or loses one.cmake/compiler-flags-gl.txt, as main's other units are; every callee they have to see is on that list already.Kept as they are
Each ratio is
quick_diffwith the callees in the unit; the text as it is reads 0.9860 (UpdateHealer) and 0.9826 (UpdateSpearman), which are full matches in the builds.ifonreturnFalseStub's result with two arms that store the same state (UpdateSpearman): see above; a comment says why.advanceMoatDigProgressandremoveMoatcompared with 1 (UpdateSpearman), as in UpdatePikeman and UpdateSlave, with a comment: a truth test reads 0.9811.else if (random <= 7)(UpdateHealer, the apothecary's choice): always true, because the number was masked with 7. The original tests it (0x00540763:cmp esi, 7), and a comment says so; a plainelsereads 0.9609.ownerfrom its first lines (0x0055DA62), and the original still reads it from the unit at five later places: three tests (0x0055DF9F, 0x0055EAC6, 0x0055EB6C), an argument ofprocessDamageToBuildingThunk(0x0055E3D2) and the wall attack's localattacker(0x0055E48C). Throughownerthey read 0.9242, 0.9479, 0.9240, 0.9363 and 0.8982.int damage;without a value (UpdateSpearman's wall attack), as in main's UpdatePikeman: both arms behind it assign it.(char)onengineerManningSiegeStateRef_checkType(once in UpdateHealer, twice in UpdateSpearman): the field isbytein the header, and the fade tests it for below 0 and for above 0, so it has to be read signed.(short)where anintis stored into ashortfield: the slot into the cloud'sunitID_healer(UpdateHealer);ALG_MoatXResultandALG_MoatYResultinto the dig target, twice each, and DirectionAlgorithmState'sorientation, twice (UpdateSpearman).ALG_MoatXResultandALG_MoatYResultareundefined4in the header (TileMapState.hpp); giving them a type is a header change with every user to measure, and it is not in this PR.(int)onmapTimeInTicksin UpdateSpearman's% 40, as in UpdatePikeman: the field isuint, and the original divides signed (0x0055DE6F:cdq,idiv).(char)ondisappearFadeAlphaCountdownand on the frame tables (bothcharin the headers),(short)onBuildingLayer[tile](short) and on both operands of the dig tile's x, and(byte)on the random number that UpdateHealer masks with 7.IsGateOrTowerArrayandanimationCycleNumberHasJustIncremented(both BOOLEnum) tested by truthiness;intcalls, the two-byte flags andDAT_UnitHasBecomeIdle(undefined4) compared with 0, as main does. That is the mix the checker notes in UpdateSpearman.else ifchain whose arms fall out, as main's UpdatePitchman is written. UpdateSpearman's cases all end inreturn;.field_0x14,field_0x66c,field_0x816c,field_0x81bc,field_0x8208and twelve fromfield_0x1c04tofield_0x1e48),Unit::field_0x3f4(ashort; UpdateHealer tests it for more than 1 in its first state) andUnit::field_0x2ac(ashort; UpdateSpearman stores 10 into it in two states).Differences from the draft
We compared the operators and literals of every test against a number with gynt's drafts. None differs in what it tests. They are the same tests written the other way round with their arms exchanged (UpdateHealer:
<= 300as> 300; UpdateSpearman:<= 70as> 70twice,<= 96as> 96,!= 1015as== 1015,>= 0as< 0,!= 1as== 1), BOOLEnum calls and fields tested by truthiness where the drafts compare with 0, and hex constants in decimal or as their enum names. We did not read the two files line by line against the drafts.Other PRs
cmake/compiler-flags-gl.txt, where this one adds two, and one entry elsewhere incmake/function-visibility.txt. Reimplement UpdateTanner, UpdateArmorer, UpdatePoleTurner, UpdateFletcher, UpdateBlacksmith and UpdateWoodcutter from gynt's units branch, 100% with OPENSHC_FUNCTION_VISIBILITY_UNITS on #536 (ours, open) adds lines at the same place and entries infunction-visibility.txttoo. Whichever of these merges later needs a small merge there: keep all the lines.computeLadderClimbPathoff the/GLlist with Take UnitsState::clearAllUnits and computeLadderClimbPath off the /GL list (both back at 100%) #541, and UpdateHealer calls it. The builds above were made after that. The earlier pair, made with that body still in sight, read UpdateHealer 100.0% too, andquick_diffgives it the same diff against the original with the body and without it (0.9860 both ways). Neither function reaches anything else that Reimplement six UnitsState functions at 100%, from gynt's text on main #539, Take UnitsState::clearAllUnits and computeLadderClimbPath off the /GL list (both back at 100%) #541 or Reimplement UnitsState::processUnitAttackOtherUnit at 100%, from gynt's text on main #542 changed on main, or that Reimplement UpdateTanner, UpdateArmorer, UpdatePoleTurner, UpdateFletcher, UpdateBlacksmith and UpdateWoodcutter from gynt's units branch, 100% with OPENSHC_FUNCTION_VISIBILITY_UNITS on #536, Reimplement UnitsState::prepareProjectileTarget at 100%, from gynt's text on main (one header line each in two files) #540 or Reimplement UnitsState::processMeleeInitiation with the original's code, from gynt's text on main #543 (ours, open) change.cmake/function-visibility.txt. Other open PRs changecmake/compiler-flags-gl.txtas well: reimpl/BuildingsState #234, Reimpl/viewport render state #241, Reimpl/tile map state #242, Reimpl/GameStateStructures development #243, Reimpl/troop value state development #275, Reimplement 17 rendering, UI and GameSynchronyState functions (not yet 100%) #313, Reimplement 2 UI::MenuItems functions (draft, below 100%) #327, Reimplement 3 UI::MenuItems functions from gynt's drafts (not yet 100%) #328, Reimplement 67 Map::TileMapState functions (batch 2) #396, Reimplement 66 TroopValueState functions at 100% #501, Reimplement 59 TextManager and UserTextHandler functions at 100% #509, Landscape and wildlife: 17 functions, 10 at 100% #526, Entities, projectiles and fire: 17 functions, 3 at 100% #527, TroopValueState leftovers: 4 functions, 2 at 100% #528 and UI menu views and modals: 9 functions, none at 100% yet #529.findBestAttackTileByPathCost,resetTileAndClearMoat,TransformAndRenderPercentage). The builds above left them out, with their resolvers off. On d134c77 more of main's.cppfiles wait for the header sync: eight still use the old nameaiControlStatusRelated, seven of them in the small builds' list, so those builds can't be made on that main yet. This PR touches none of these files.🤖 Generated with Claude Code